package com.csaba.connector.bha.model;

import com.csaba.connector.bha.SimpleNodeHelper;
import com.csaba.connector.model.Amount;
import com.csaba.connector.model.Customer;
import com.ind.simplenode.SimpleNode;

public class BHADepositAccount extends BHAAccount
{
	private static final long serialVersionUID = -3363497403238282155L;

	private String branch;
	private String depositType;
	private String reference;

	public BHADepositAccount()
	{
		super();
	}

	public BHADepositAccount( final Customer customer, final SimpleNode properties )
	{
		super(customer, properties);

		//set base fields
		branch = SimpleNodeHelper.getAndRemove(properties, "branch");
		depositType = SimpleNodeHelper.getAndRemove(properties, "type");
		reference = SimpleNodeHelper.getAndRemove(properties, "reference");

		setNumber(branch + " " + depositType + " " + reference);

		final String fromBranch = SimpleNodeHelper.getAndRemove(properties, "fromBranch");
		final String fromCustomer = SimpleNodeHelper.getAndRemove(properties, "fromCustomerId");
		final String fromSuffix = SimpleNodeHelper.getAndRemove(properties, "fromSuffix");
		properties.set("fromAccount", fromBranch + "-" + fromCustomer + "-" + fromSuffix);

		final String toBranch = SimpleNodeHelper.getAndRemove(properties, "toBranch");
		final String toCustomer = SimpleNodeHelper.getAndRemove(properties, "toCustomerId");
		final String toSuffix = SimpleNodeHelper.getAndRemove(properties, "toSuffix");
		properties.set("toAccount", toBranch + "-" + toCustomer + "-" + toSuffix);

		final String interestBranch = SimpleNodeHelper.getAndRemove(properties, "interestBranch");
		final String interestCustomer = SimpleNodeHelper.getAndRemove(properties, "interestCustomerId");
		final String interestSuffix = SimpleNodeHelper.getAndRemove(properties, "interestSuffix");
		properties.set("interestAccount", interestBranch + "-" + interestCustomer + "-" + interestSuffix);

		setIBAN(null); //IBAN is not available for deposits 
		setName(null); //friendly name is not set for deposits
		setType(properties.getStringPath("period.text") + " lek\u00F6t\u00E9s");
		setAvailableBalance(new Amount(0, getCurrency()));

		final String current = SimpleNodeHelper.getAndRemove(properties, "currentBalance");
		setBookedBalance(new Amount(Double.valueOf(current), getCurrency()));

		//set special fields
		SimpleNodeHelper.setAmountProperty(this, properties, "balanceAtNextTurn", getCurrency());
		SimpleNodeHelper.setAmountProperty(this, properties, "grossInterestAmount", getCurrency());
		SimpleNodeHelper.setAmountProperty(this, properties, "interestAmount", getCurrency());
		SimpleNodeHelper.setAmountProperty(this, properties, "interestTaxAmount", getCurrency());
		//SimpleNodeHelper.setAmountProperty(this, properties, "nextCapitalModifyAmount", getCurrency());
		SimpleNodeHelper.setAmountProperty(this, properties, "openBalance", getCurrency());
		SimpleNodeHelper.setAmountProperty(this, properties, "todayInterest", getCurrency());
		SimpleNodeHelper.setDateProperty(this, properties, "openDate");
		SimpleNodeHelper.setDateProperty(this, properties, "nextDate");

		// set remaining fields
		//SimpleNodeHelper.loadProperties(this, properties);
	}

	/*	DEPOSITS
		.response.deposits[0].balanceAtNextTurn = '#0.00'
	.response.deposits[0].blockingNarrative = '???????'
	.response.deposits[0].branch = 'MISK'
	.response.deposits[0].capitalized = 'true'
	.response.deposits[0].cautionFlag = 'false'
	.response.deposits[0].currency = 'HUF'
	.response.deposits[0].currentBalance = '#0.00'
	.response.deposits[0].fromBranch = 'xxxx'
	.response.deposits[0].fromCustomerId = 'xxxxxxx'
	.response.deposits[0].fromSuffix = 'xxx'
		.response.deposits[0].grossInterestAmount = '#0.00'
	.response.deposits[0].interest = '#0.000000'
		.response.deposits[0].interestAmount = '#0.00'
	.response.deposits[0].interestBranch = 'xxxx'
	.response.deposits[0].interestCustomerId = 'xxxxxx'
	.response.deposits[0].interestSuffix = 'xxx'
		.response.deposits[0].interestTaxAmount = '#0.00'
	.response.deposits[0].interestTaxRate = '#0.0000000'
	.response.deposits[0].modifyEnabled = 'true'
		.response.deposits[0].nextCapitalModifyAmount = '#0.00'
	.response.deposits[0].nextDate = 'yyyyMMddHHmmSS'
		.response.deposits[0].openBalance = '#0.00'
	.response.deposits[0].openDate = 'yyyyMMddHHmmSS'
	.response.deposits[0].period.code = '1M'
	.response.deposits[0].period.text = '1 Havi'
	.response.deposits[0].possiblePartBreak = 'false'
	.response.deposits[0].prevDate = 'yyyyMMddHHmmSS'
	.response.deposits[0].reference = '????????'
	.response.deposits[0].toBranch = 'xxxx'
	.response.deposits[0].toCustomerId = 'xxxxxxx'
	.response.deposits[0].toSuffix = 'xxx'
		.response.deposits[0].todayInterest = '#0.00'
	.response.deposits[0].type = 'LHF'

	*/

	public String getBranch()
	{
		return branch;
	}

	public String getDepositType()
	{
		return depositType;
	}

	public String getReference()
	{
		return reference;
	}

}
